#include "MapManager.h"
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

MapManager* MapManager::sInstance   = NULL;

MapManager* MapManager::CreateInstance()
{
	if(sInstance!=NULL)return sInstance;
	else

		sInstance = new MapManager();
	return sInstance;
}

bool MapManager::parseMapFile(char8_t* fileName)
{
	FILE* fp;
	trackList = new list<trackInfoT>();
	if(!(fp = fopen(fileName,"r+")))
	{
		printf("open map file error\n");
		//return false;
	}

	//put the map info into the trackList
	trackInfoT* _temp;
	_temp = new trackInfoT();
	while(fscanf(fp, "%d%f%f%f%f%f%f", &(_temp->trackType), &(_temp->posX), &(_temp->posY), &(_temp->posZ),
		&(_temp->scaleX), &(_temp->scaleY), &(_temp->scaleZ))!=EOF)
	{
		_temp->posZ *= -1;//flip for the unity generate map file

		trackList->push_back(*_temp);
		_temp = new trackInfoT();
	}

	return true;
}

